package com.gx.project.controller;

import com.gx.common.result.ResponseResult;
import com.gx.project.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * @author gx
 * @description
 */
@RestController
@RequestMapping("/user")
@Validated
public class UserController {


    @Autowired
    private UserService userService;


    /**
     * 添加用户
     * @param name
     * @return
     */
    @PostMapping("/addUser")
    public ResponseResult applyToSupplier(@NotNull(message = "name必填") String name){
        try{
            return userService.addUser(name);
        }
        catch (Exception ex){
            return ResponseResult.failInstance(ex.getMessage());
        }
    }


    /**
     * 删除用户
     * @param id
     */
    @RequestMapping("/deleteUser")
    public ResponseResult deleteUser(@NotNull(message = "id必填") Long id){
        try{
            userService.removeById(id);
            return ResponseResult.successInstance();
        }
        catch (Exception ex){
            return ResponseResult.failInstance(ex.getMessage());
        }
    }





}
